Telegram Group & Telegram Channel
💡 Структура CLI-приложения на Go

Когда мы пишем CLI на Go, важно грамотно организовать структуру проекта. Вот распространённый и удобный шаблон:


my-cli/
├── cmd/
│ ├── root.go
│ └── greet.go
├── internal/
│ └── greet/
│ └── greet.go
├── main.go
├── go.mod


📌 Основные моменты:

- main.go — точка входа. Здесь мы вызываем cmd.Execute().
- Папка cmd/ содержит все команды CLI. Например, greet.go реализует команду greet, а root.go — основную/root-команду.
- В internal/greet/greet.go размещаем бизнес-логику, отделяя её от логики CLI. Это улучшает читаемость, покрытие тестами и повторное использование кода.

📁 Пример содержимого cmd/greet.go:

var greetCmd = &cobra.Command{
Use: "greet",
Short: "Выводит приветствие",
Run: func(cmd *cobra.Command, args []string) {
greet.SayHello()
},
}


А в internal/greet/greet.go:

func SayHello() {
fmt.Println("Привет от Go CLI!")
}


📦 Такой подход делает CLI-приложение масштабируемым и удобным для поддержки. Особенно если вы планируете добавлять новые команды или делегировать разработку другим.

https://www.bytesizego.com/blog/structure-go-cli-app

👉 @golang_lib



tg-me.com/golang_lib/460
Create:
Last Update:

💡 Структура CLI-приложения на Go

Когда мы пишем CLI на Go, важно грамотно организовать структуру проекта. Вот распространённый и удобный шаблон:


my-cli/
├── cmd/
│ ├── root.go
│ └── greet.go
├── internal/
│ └── greet/
│ └── greet.go
├── main.go
├── go.mod


📌 Основные моменты:

- main.go — точка входа. Здесь мы вызываем cmd.Execute().
- Папка cmd/ содержит все команды CLI. Например, greet.go реализует команду greet, а root.go — основную/root-команду.
- В internal/greet/greet.go размещаем бизнес-логику, отделяя её от логики CLI. Это улучшает читаемость, покрытие тестами и повторное использование кода.

📁 Пример содержимого cmd/greet.go:

var greetCmd = &cobra.Command{
Use: "greet",
Short: "Выводит приветствие",
Run: func(cmd *cobra.Command, args []string) {
greet.SayHello()
},
}


А в internal/greet/greet.go:

func SayHello() {
fmt.Println("Привет от Go CLI!")
}


📦 Такой подход делает CLI-приложение масштабируемым и удобным для поддержки. Особенно если вы планируете добавлять новые команды или делегировать разработку другим.

https://www.bytesizego.com/blog/structure-go-cli-app

👉 @golang_lib

BY Библиотека Go (Golang) разработчика


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/golang_lib/460

View MORE
Open in Telegram


Библиотека Go Golang разработчика Telegram | DID YOU KNOW?

Date: |

For some time, Mr. Durov and a few dozen staffers had no fixed headquarters, but rather traveled the world, setting up shop in one city after another, he told the Journal in 2016. The company now has its operational base in Dubai, though it says it doesn’t keep servers there.Mr. Durov maintains a yearslong friendship from his VK days with actor and tech investor Jared Leto, with whom he shares an ascetic lifestyle that eschews meat and alcohol.

That growth environment will include rising inflation and interest rates. Those upward shifts naturally accompany healthy growth periods as the demand for resources, products and services rise. Importantly, the Federal Reserve has laid out the rationale for not interfering with that natural growth transition.It's not exactly a fad, but there is a widespread willingness to pay up for a growth story. Classic fundamental analysis takes a back seat. Even negative earnings are ignored. In fact, positive earnings seem to be a limiting measure, producing the question, "Is that all you've got?" The preference is a vision of untold riches when the exciting story plays out as expected.

Библиотека Go Golang разработчика from pl


Telegram Библиотека Go (Golang) разработчика
FROM USA